(function(window, undefined) {
	var staticObj = cc.Sprite.extend({
		ctor: function(opts) {
			//初始化状态列表
			this.name = opts.name;
			this.statusArr = ['create', 'normal', 'hited', 'dead'];
			this.initWithTexture(cc.TextureCache.getInstance().addImage(opts.filename), opts.rect);
			this.setContentSize(opts.size);

			// events
			if(opts.handle) {
				var handleList = opts.handle;
				for(var i in handleList) {
					var handName = i;
					var handFn = handleList[i];
					console.log(handName,handFn);
					this.attach(i, handFn.bind(this));
				}

			}



		},
		onEnter: function() {
			this._super();
			this.changeStatus('create');
		},
		// name
		name: null,
		// attr
		type: null,
		// 皮肤枚举(动画)
		skinArr: null,
		// 当前皮肤
		skin: null,
		// 属性
		prop: null,
		// 可否碰撞
		hitable: null,
		// 状态枚举
		statusArr: null,
		// 当前状态
		status: null,
		// method
		changeStatus: function(statName) {
			var rst = true;
			var index = this.statusArr.indexOf(statName);
			if(index >= 0) {
				var lastStatus = this.status;
				if(lastStatus == statName) {
					console.info("no status changed!!");
					rst = false;
				} else {
					this.status = this.statusArr[index];
					this.trigger('afterStatusChanged', {
						ostat: lastStatus,
						nstat: this.status
					});
					rst = true;
				}
			} else {
				console.info("no such status " + statName);
				rst = false;
			}
			return rst;
		},
		changeSkin: function(skinName, callback) {


			this.stopAllActions();

			var animation = dino.getSkin(this.name, skinName);
			if(animation) {
				var animate = cc.Animate.create(animation);
				var rpt = cc.RepeatForever.create(animate);
				this.runAction(rpt);
			} else {
				throw "no such skin " + skinName;
			}
			callback && callback();

		},

		// 绑定事件
		attach: function(eventName, fn) {
			var dic = this.__eventList__ = this.__eventList__ || {};
			var edic = dic[eventName] = dic[eventName] || {};
			var eid = new Date().getTime();
			edic[eid] = fn;
			return eid;
		},
		// 反绑定事件
		// 如果eid为空,则全部都反绑定
		detach: function(eventName, eid) {
			var dic = this.__eventList__ = this.__eventList__ || {};
			var edic = dic[eventName] = dic[eventName] || {};
			if(eid !== undefined) {
				if(edic[i]) {
					delete edic[i];
				}
			} else {
				for(var i in edic) {
					delete edic[i];
				}
			}
		},
		// 触发
		trigger: function(eventName, opts) {
			var dic = this.__eventList__ = this.__eventList__ || {};
			var edic = dic[eventName] = dic[eventName] || {};
			for(var i in edic) {
				edic[i](opts);
			}
		}
	});
	window.staticObj = staticObj;
})(window);